var logUtils = require ('../log/logUtils');
var deviceUtils = require ('../device/deviceUtils');
var clickUtils = require ('../click/clickUtils');
var pointMap = {
  关闭所有应用: [[420, 2006, 660, 2246], 1080, 2340],
};
module.exports = {
  appName: null,
  openApp (appName) {
    this.appName = appName;
    var result = app.launchApp (appName);
    logUtils.log ('打开：', appName, result ? '成功' : '失败');
    sleep (2 * 1000);
    return result;
  },
  closeRecent () {
    deviceUtils.home ();
    sleep (2 * 1000);
    deviceUtils.recents ();
    sleep (2 * 1000);
    if (['cannon', 'evergo'].includes (device.product)) {
      swipe (
        device.width / 4 + device.width / 8 + device.width / 16,
        device.height / 2,
        device.width / 20,
        device.height / 2,
        200
      );
    } else {
      swipe (
        device.width / 2,
        device.height / 2,
        device.width / 2,
        device.height / 16,
        randomUtils.getRandom (300, 500)
      );
    }
    sleep (2 * 1000);
    deviceUtils.home ();
    sleep (2 * 1000);
  },
  closeAll () {
    deviceUtils.home ();
    sleep (2 * 1000);
    deviceUtils.recents ();
    sleep (2 * 1000);
    clickUtils.clickPointMap (pointMap.关闭所有应用);
    sleep (2 * 1000);
  },
  checkInstall (appName) {
    return !!app.getPackageName (appName);
  },
};
